package com.daona.application.kafka;

import com.daona.model.constants.Constants;
import com.daona.model.message.PdfMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class Producer {

    private final KafkaTemplate<String, PdfMessage> kafkaTemplate;

    public void sendMsg (PdfMessage message){
        try {
            // 发送消息
            kafkaTemplate.send(Constants.TOPIC_PDF, message.getKey(), message);
            log.info("send msg:{} successfully",message);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}
